import Queue
import threading
import requests
head={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0; SE 2.X MetaSr 1.0) like Gecko"}

proxy_ips=[]
class check(threading.Thread):
    def __init__(self,queue):
        threading.Thread.__init__(self)
        self._queue=queue
    def run(self):
        while not self._queue.empty():
            ip=self._queue.get()
            ip = eval(ip)
            try:
                respon=requests.get("http://www.baidu.com",headers=head,proxies=ip,timeout=4)
            except:
                respon=None
            if respon is not None:
                proxy_ips.append(ip)


def put():
    threads=[]
    thread_count=10
    fileA = open("proxy_ips.txt", "r")
    queue=Queue.Queue()
    for ip in fileA.readlines():
        ip.replace("\r\n",'')
        queue.put(ip)
    fileA.close()
    for i in range(thread_count):
        threads.append(check(queue))
    for i in range(thread_count):
        threads[i].start()
    for i in range(thread_count):
        threads[i].join()
    fileB = open("proxy_ips.txt", "w")
    for ip in proxy_ips:
        fileB.write(str(ip))
        fileB.write("\r\n")
    fileB.close()
if __name__=="__main__":
    put()